<template>
  <div class="mod-config">
    <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
      <el-form-item>
      <!--  <el-input v-model="dataForm.key" placeholder="参数名" clearable></el-input>-->


        <el-select clearable v-model="dataFormQuery.companyPropertyId" placeholder="请选择企业的性质" clearable>
          <el-option
            v-for="item in selectOption"
            :key="item.value"
            :label="item.label"
            :value="item.value">
          </el-option>
        </el-select>


        <el-cascader
          clearable
          placeholder="请选择行业信息"
          v-model="dataForm.industryOptions"
          :options="industryOptions"
          @change="handleChangeIndustoryCondition">
        </el-cascader>


        <el-cascader
          clearable
          placeholder="请选择地址信息"
          v-model="dataForm.companyAddressOptions"
          :options="companyAddressOptions"
          @change="handleChangeAddressCondition">
        </el-cascader>




      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">查询</el-button>
        <el-button v-if="isAuth('companys:company:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
        <el-button v-if="isAuth('companys:company:delete')" type="danger" @click="deleteHandle()" :disabled="dataListSelections.length <= 0">批量删除</el-button>
      </el-form-item>
    </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <el-table-column type="expand">
        <template slot-scope="props">
          <el-form label-position="left" inline class="demo-table-expand">

            <el-form-item label="企业性质:">
              <el-tag size="small" v-if="props.row.companyPropertyId == '1'">国有企业</el-tag>
              <el-tag size="small" v-else-if="props.row.companyPropertyId == '2'">集体企业</el-tag>
              <el-tag size="small" v-else-if="props.row.companyPropertyId == '3'">联营企业</el-tag>
              <el-tag size="small" v-else-if="props.row.companyPropertyId == '4'">股份合作制企业</el-tag>
              <el-tag size="small" v-else-if="props.row.companyPropertyId == '5'">私营企业</el-tag>
              <el-tag size="small" v-else-if="props.row.companyPropertyId == '6'">个体户合伙企业</el-tag>
              <el-tag size="small" v-else-if="props.row.companyPropertyId == '7'">有限责任公司</el-tag>
              <el-tag size="small" v-else-if="props.row.companyPropertyId == '8'">股份有限公司</el-tag>
              <!--<span>{{props.row.companyPropertyId}}</span>-->
            </el-form-item>

            <el-form-item label="注册资金:">
              <span>{{props.row.registerMany}}人民币</span>
            </el-form-item>

            <el-form-item label="联系人:">
              <span>{{ props.row.companyContact }}</span>
            </el-form-item>
            <el-form-item label="电话:">
              <span>{{ props.row.companyPhone }}</span>
            </el-form-item>
            <el-form-item label="微信:">
              <span>{{ props.row.companyWechat }}</span>
            </el-form-item>
            <el-form-item label="固话:">
              <span>{{ props.row.companyFixPhone }}</span>
            </el-form-item>
            <el-form-item label="邮箱:">
              <span>{{ props.row.companyEmail }}</span>
            </el-form-item>
            <el-form-item label="QQ:">
              <span>{{ props.row.companyQq }}</span>
            </el-form-item>

            <el-form-item label="企业介绍:">
              <span>{{ props.row.companyIntrl }}</span>
            </el-form-item>

            <el-form-item label="详细地址:">
              <span>{{ props.row.detailPosition }}</span>
            </el-form-item>
          </el-form>
        </template>
      </el-table-column>

      <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column>

      <el-table-column
        prop="companyName"
        header-align="center"
        align="center"
        label="企业名称"
        width="220">
      </el-table-column>

      <el-table-column
        prop="companyUrl"
        header-align="center"
        align="center"
        label="企业官网"
        width="260">
      </el-table-column>

      <el-table-column
        prop="companyApproveStatus"
        header-align="center"
        align="center"
        label="审核状态"
        width="130">

        <template slot-scope="scope">
          <el-tag v-if="scope.row.companyApproveStatus == 10410" type="danger">未审核</el-tag>
          <el-tag v-else-if="scope.row.companyApproveStatus == 10420" type="warning">审核中</el-tag>
          <el-tag v-else-if="scope.row.companyApproveStatus == 10430" type="success">已审核</el-tag>
        </template>

      </el-table-column>

      <el-table-column
        prop="isPass"
        header-align="center"
        align="center"
        label="是否通过审核"
        width="130">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.isPass == 1" type="success">已通过</el-tag>
          <el-tag v-else type="danger">未通过</el-tag>
        </template>


      </el-table-column>

      <el-table-column
        fixed="right"
        header-align="center"
        align="center"
        width="310"
        label="操作">
        <template slot-scope="scope">
          <el-button type="text" size="small" @click="queryShowDetailInfo(scope.row)">查看详情</el-button>
          <el-button type="text" size="small" @click="companyApprovePass(scope.row)">审核通过</el-button>
          <el-button type="text" size="small" @click="companyApproveNotPass(scope.row)">审核不通过</el-button>
          <el-button type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">修改</el-button>
          <el-button type="text" size="small" @click="deleteHandle(scope.row.id)">删除</el-button>
        </template>
      </el-table-column>

    </el-table>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>


    <el-dialog
      title="企业详情"
      :close-on-click-modal="false"
      :visible.sync="companyDetailvisible">
      <el-form :model="dataForm"
               ref="dataForm"
               label-width="130px"
               :inline="true">
        <el-form-item label="企业名称" prop="companyName">
          <el-col :span="20">
            <el-input  disabled v-model="dataForm.companyName" placeholder="企业名称"></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="企业性质" prop="companyPropertyId">
          <template>
            <el-col :span="22">
              <el-select disabled v-model="dataForm.companyPropertyId" placeholder="请选择">
                <el-option
                  v-for="item in selectOption"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value">
                </el-option>
              </el-select>
            </el-col>
          </template>
          <!--      <el-input v-model="dataForm.companyPropertyId" placeholder="企业性质"></el-input>-->

        </el-form-item>
        <el-form-item label="注册资金" prop="registerMany">
          <el-col :span="20">
            <el-input disabled v-model="dataForm.registerMany" placeholder="注册资金"></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="企业官网" prop="companyUrl">
          <el-col :span="24">
            <el-input disabled v-model="dataForm.companyUrl" placeholder="企业官网"></el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="所属行业">
          <el-col :span="19">
            <el-cascader
              disabled
              v-model="dataForm.industryOptions"
              :options="industryOptions"
              >
            </el-cascader>
          </el-col>
        </el-form-item>

        <el-form-item label="企业地址" label-width="115px">
          <el-col :span="22">
            <el-cascader disabled
              v-model="dataForm.companyAddressOptions"
              :options="companyAddressOptions"
              >
            </el-cascader>
          </el-col>
        </el-form-item>

        <el-form-item label="联系人" prop="companyContact">
          <el-col :span="20">
            <el-input disabled v-model="dataForm.companyContact" placeholder="联系人"></el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="联系电话" prop="companyPhone">
          <el-col :span="24">
            <el-input disabled v-model="dataForm.companyPhone" placeholder="联系电话"></el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="联系微信" prop="companyWechat">
          <el-col :span="20">
            <el-input disabled v-model="dataForm.companyWechat" placeholder="联系微信"></el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="联系固话" prop="companyFixPhone">
          <el-col :span="24">
            <el-input disabled v-model="dataForm.companyFixPhone" placeholder="联系固话"></el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="联系邮箱" prop="companyEmail">
          <el-col :span="20">
            <el-input disabled v-model="dataForm.companyEmail" placeholder="联系邮箱"></el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="联系QQ" prop="companyQq">
          <el-col :span="24">
            <el-input disabled v-model="dataForm.companyQq" placeholder="联系QQ"></el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="详细地址" prop="detailPosition">
          <el-col :span="20">
            <el-input disabled v-model="dataForm.detailPosition" placeholder="详细地址"></el-input>
          </el-col>
        </el-form-item>

        <el-form-item label="企业福利" prop="detailPosition">
          <el-col :span="24">
            <el-select
              disabled
              style="width: 300px"
              v-model="dataForm.companyWalfare"
              clearable
              multiple
              placeholder="请选择">
              <el-option
                v-for="item in walfareOption"
                :key="item.value"
                :label="item.label"
                :value="item.value">
              </el-option>
            </el-select>
          </el-col>
        </el-form-item>

        <el-form-item label="企业介绍" prop="companyIntrl">
          <el-col :span="24">
            <el-input
              disabled
              style="width: 500px"
              type="textarea"
              maxlength="100"
              :rows = "5"
              show-word-limit v-model="dataForm.companyIntrl"
              placeholder="企业介绍">
            </el-input>
          </el-col>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
      <el-button @click="closeCompanyDetailvisible()">关闭页面</el-button>

    </span>
    </el-dialog>
  </div>
</template>

<script>
  import AddOrUpdate from './company-add-or-update'

  export default {
    inject:['reload'],
    data () {
      return {

        companyDetailvisible:false,         //详情页面的弹窗

        dataFormQuery:{
          provincesId: undefined,
          cityesId: undefined,
          areasId: undefined,
          tradeId: undefined,
          classifyId: undefined,
          jobTypeId: undefined,
          companyPropertyId:undefined
        },



        dataForm: {
          id: 0,
          companyWalfare:[],
          companyName: '',
          registerMany: '',
          companyUrl: '',
          companyContact: '',
          companyPhone: '',
          companyWechat: '',
          companyFixPhone: '',
          companyEmail: '',
          companyQq: '',
          provincesId: '',
          cityesId: '',
          areasId: '',
          tradeId: '',
          classifyId: '',
          jobTypeId: '',
          industryOptions:[],
          companyAddressOptions:[],
          detailPosition: '',
          companyIntrl: '',
          companyPropertyId: '',
        },

        walfareOption:[],
        selectOption:[],
        industryOptions:[],
        companyAddressOptions:[],

        dataList: [],
        pageIndex: 1,
        pageSize: 10,
        totalPage: 0,
        dataListLoading: false,
        dataListSelections: [],
        addOrUpdateVisible: false,



        isPass:0,      //是否通过审核
      }
    },
    components: {
      AddOrUpdate
    },
    activated () {
      this.getDataList()
    },
    mounted () {
      this.loadingIndustory()
      this.loadingCompanyAddress()
      this.loadingCompanyProperty()
      this.loadingCompanyWalfare()
    },
    methods: {
      //关闭详情的Dialog
      closeCompanyDetailvisible(){
        this.companyDetailvisible = false;
        this.reload()
      },


      //加载行业选项
      loadingIndustory(){
        this.$http({
          url: this.$http.adornUrl('/workjobs/workjob/tree-option-ccj'),
          method: 'get',
        }).then(({data}) => {
          if (data && data.code === 0){
            this.industryOptions = data.data
          }
        })
      },
      //加载企业地址选项
      loadingCompanyAddress(){
        this.$http({
          url: this.$http.adornUrl('/companys/company/tree-option-pcr'),
          method: 'get',
        }).then(({data}) => {
          if (data && data.code === 0){
            this.companyAddressOptions = data.data
          }
        })
      },
      //加载企业的性质
      loadingCompanyProperty(){
        this.$http({
          url: this.$http.adornUrl('/common/companyproperty/list-option'),
          method: 'get',
        }).then(({data}) => {
          console.log("data",data)
          if (data && data.code === 0){
            this.selectOption = data.data
          }
        })
      },
      //加载企业福利列表
      loadingCompanyWalfare(){
        this.$http({
          url: this.$http.adornUrl('/common/welfare/select-option'),
          method: 'get',
        }).then(({data}) => {
          console.log("data",data)
          if (data && data.code === 0){
            this.walfareOption = data.data
          }
        })
      },

      // 获取数据列表
      getDataList () {
        this.dataListLoading = true
        this.$http({
          url: this.$http.adornUrl('/companys/company/list'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'key': this.dataForm.key,
            'queryCondition':this.dataFormQuery
          })
        }).then(({data}) => {
          console.log(data)
          if (data && data.code === 0) {
            this.dataList = data.page.list
            this.totalPage = data.page.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      },
      // 每页数
      sizeChangeHandle (val) {
        this.pageSize = val
        this.pageIndex = 1
        this.getDataList()
      },
      // 当前页
      currentChangeHandle (val) {
        this.pageIndex = val
        this.getDataList()
      },
      // 多选
      selectionChangeHandle (val) {
        this.dataListSelections = val
      },
      // 新增 / 修改
      addOrUpdateHandle (id) {
        this.addOrUpdateVisible = true
        this.$nextTick(() => {
          this.$refs.addOrUpdate.init(id)
        })
      },
      // 删除
      deleteHandle (id){
        var ids = id ? [id] : this.dataListSelections.map(item => {
          return item.id
        })
        this.$confirm(`此操作会将您创建的职位一并删除，确定执行操作?`, '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$http({
            url: this.$http.adornUrl('/companys/company/delete'),
            method: 'post',
            data: this.$http.adornData(ids, false)
          }).then(({data}) => {
            if (data && data.code === 0) {
              this.$message({
                message: '操作成功',
                type: 'success',
                duration: 1500,
                onClose: () => {
                  this.getDataList()
                }
              })
            } else {
              this.$message.error(data.msg)
            }
          })
        })
      },

      //查看详情
      queryShowDetailInfo(object){
        this.$http({
          url:this.$http.adornUrl('/companys/company/tree-option-need-info/' + object.id),
          method:'get'
        })
          .then(data => {
            console.log("data",data)
            if (data && data.data.code === 0){
              this.dataForm.companyWalfare = data.data.listDataWelfare
              this.dataForm.industryOptions = data.data.listDataIndustory
              this.dataForm.companyAddressOptions = data.data.listDataAddress
            }
          })


            this.$http({
              url: this.$http.adornUrl('/companys/company/info/' + object.id),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              console.log("data init===>> ",data)
              if (data && data.code === 0) {
                this.dataForm.companyName = data.company.companyName
                this.dataForm.registerMany = data.company.registerMany
                this.dataForm.companyUrl = data.company.companyUrl
                this.dataForm.companyContact = data.company.companyContact
                this.dataForm.companyPhone = data.company.companyPhone
                this.dataForm.companyWechat = data.company.companyWechat
                this.dataForm.companyFixPhone = data.company.companyFixPhone
                this.dataForm.companyEmail = data.company.companyEmail
                this.dataForm.companyQq = data.company.companyQq
                this.dataForm.provincesId = data.company.provincesId
                this.dataForm.cityesId = data.company.cityesId
                this.dataForm.areasId = data.company.areasId
                this.dataForm.detailPosition = data.company.detailPosition
                this.dataForm.companyIntrl = data.company.companyIntrl
                this.dataForm.tradeId = data.company.tradeId
                this.dataForm.classifyId = data.company.classifyId
                this.dataForm.jobTypeId = data.company.jobTypeId
                this.dataForm.companyPropertyId = data.company.companyPropertyId.toString()
              }
            })

        this.$http({
          url: this.$http.adornUrl('/companys/company/updateCompanyStatus/' + object.id),
          method: 'post',
        })
        .then(data => {
          //this.reload()
        })

        this.companyDetailvisible = true
      },
      //企业资质审核通过
      companyApprovePass(object){
        const companyId = object.id
        this.isPass = 1
        this.$http({
          url: this.$http.adornUrl('/companys/company/approve/' + companyId + "/" + this.isPass),
          method: 'post',
        }).then(({data}) => {
          //console.log(" post===> ",data)
          if (data && data.code === 0){
            if (data.data){
              this.$message({
                type:'success',
                message:'通过审核'
              })
              this.reload()
            }
          }else if (data && data.code === 500){
            this.$message({
              type:'warning',
              message:data.msg
            })
          }
        })
      },
      //企业资质审核通过
      companyApproveNotPass(object){
        const companyId = object.id
        this.isPass = 0
        this.$http({
          url: this.$http.adornUrl('/companys/company/approve/' + companyId + "/" + this.isPass),
          method: 'post',
        }).then(({data}) => {
          //console.log(" post===> ",data)
          if (data && data.code === 0){
            if (data.data){
              this.$message({
                type:'success',
                message:'通过审核'
              })
              this.reload()
            }
          }else if (data && data.code === 500){
            this.$message({
              type:'warning',
              message:data.msg
            })
          }
        })
      },
      //行业信息
      handleChangeIndustoryCondition(value){
        console.log("vlaue indeutory====>",value  )
        this.dataFormQuery.tradeId = value[0]
        this.dataFormQuery.classifyId = value[1]
        this.dataFormQuery.jobTypeId = value[2]
      },

      //地址信息
      handleChangeAddressCondition(value){
        console.log("vlaue Address====>",value  )
        this.dataFormQuery.provincesId = value[0]
        this.dataFormQuery.cityesId = value[1]
        this.dataFormQuery.areasId = value[2]
      }
    }
  }
</script>

<style scoped>
  .demo-table-expand {
    font-size: 0;
  }
  .demo-table-expand label {
    width: 90px;
    color: #99a9bf;
  }
  .demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 50%;
  }  .demo-table-expand {
       font-size: 0;
     }
  .demo-table-expand label {
    width: 90px;
    color: #99a9bf;
  }
  .demo-table-expand .el-form-item {
    margin-right: 0;
    margin-bottom: 0;
    width: 50%;
  }
</style>
